package online.westonline.com.westonline.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.google.gson.Gson;


import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import online.westonline.com.westonline.R;
import online.westonline.com.westonline.entry.IamgeBean;
import online.westonline.com.westonline.entry.NodeBean;

/**
 *
 *
 * Created by xiatao on 2018/7/25.
 */

public class NodeInfoAdpter extends RecyclerView.Adapter<NodeInfoAdpter.NodeViewHolder> {



    private List<NodeBean> datas = new ArrayList<>();

    public void setDatas(List<NodeBean> datas) {
        this.datas = datas;
    }

    @NonNull
    @Override
    public NodeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.node_info_real_item, parent, false);
        return new NodeViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull NodeViewHolder holder, int position) {
        NodePerviewadapter perviewInfoAdpter = new NodePerviewadapter();
        NodeBean bean = datas.get(position);
        holder.tvNodeEditTime.setText("于" + bean.getTime() + "编辑");
        holder.tvNodeInfoContent.setText("\t\t\t" + bean.getContent());
        holder.recyclerviewImginfo.setLayoutManager(new GridLayoutManager(holder.itemView.getContext(), 3, GridLayoutManager.VERTICAL, false));
        holder.recyclerviewImginfo.setAdapter(perviewInfoAdpter);
        holder.tvNodeInfoTitle.setText(bean.getTitle());
        if (!TextUtils.isEmpty(bean.getImg_paths())) {
            perviewInfoAdpter.setPaths(new Gson().fromJson(bean.getImg_paths(), IamgeBean.class).getPaths());
        } else {
            holder.recyclerviewImginfo.setVisibility(View.GONE);
        }
        holder.recyclerviewImginfo.setNestedScrollingEnabled(false);
    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    class NodeViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_node_edit_time)
        TextView tvNodeEditTime;
        @BindView(R.id.tv_node_info_title)
        TextView tvNodeInfoTitle;
        @BindView(R.id.tv_node_info_content)
        TextView tvNodeInfoContent;
        @BindView(R.id.recyclerview_imginfo)
        RecyclerView recyclerviewImginfo;
        @BindView(R.id.tv_node_change)
        TextView tvNodeChange;
        @BindView(R.id.tv_node_info_delete)
        TextView tvNodeInfoDelete;

        public NodeViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
